package hangMan;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JPanel;

public class HangManDraw extends JPanel {
	
	Words gamePanel;
	
	public HangManDraw(){
		setLayout(new BorderLayout());

	}

	private int errors = 0;
	
	
	
	

	public void setErrors(int errors) {
		this.errors = errors;
	}

	public int getErrors() {
		return errors;
	}

	public void defaultErrors() {
		errors = 0;
	}

	public void refreshErrors() {
		errors++;
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.black);
		if (errors >= 1) {
			drawGround(g);
		}
		if (errors >= 2) {
			drawHangBase(g);
		}
		if (errors >= 3) {
			drawHangArm(g);
			drawHangRope(g);
		}
		if (errors >= 4) {
			drawHead(g);
		}
		if (errors >= 5) {
			drawBody(g);
		}
		if (errors >= 6) {
			drawRightArm(g);
		}
		if (errors >= 7) {
			drawLeftArm(g);
		}
		if (errors >= 8) {
			drawLeftLeg(g);
		}
		if (errors >= 9) {
			drawRightLeg(g);
			drawDeadSing(g);
		}

		 if (errors == -1) {
		 drawWinSing(g);
		 }

	}

	private void drawGround(Graphics g) {
		g.drawLine(125, 400, 450, 400);
	}

	private void drawHangBase(Graphics g) {
		g.drawLine(250, 125, 250, 400);
	}

	private void drawHangArm(Graphics g) {
		g.drawLine(250, 125, 410, 125);
	}

	private void drawHangRope(Graphics g) {
		g.drawLine(410, 125, 410, 160);
	}

	private void drawHead(Graphics g) {
		g.drawOval(387, 160, 45, 45);
		g.fillOval(395, 175, 7, 7);
		g.fillOval(415, 175, 7, 7);
		g.drawLine(417, 193, 405, 195);
	}

	private void drawBody(Graphics g) {
		g.drawLine(410, 205, 410, 280);
	}

	private void drawRightArm(Graphics g) {
		g.drawLine(410, 215, 445, 235);
	}

	private void drawLeftArm(Graphics g) {
		g.drawLine(410, 215, 375, 235);
	}

	private void drawLeftLeg(Graphics g) {
		g.drawLine(410, 280, 445, 325);
	}

	private void drawRightLeg(Graphics g) {
		g.drawLine(410, 280, 375, 325);
	}

	private void drawDeadSing(Graphics g) {
		g.setColor(Color.RED);
		Font font = new Font(g.getFont().getName(), Font.BOLD, 15);
		g.setFont(font);
		g.drawString("You are DEAD. GAME OVER!", 315, 340);
		g.setColor(Color.BLACK);
		g.setFont(font.deriveFont(Font.PLAIN, 11));
		g.drawString("Press RESTART.", 370, 360);
	}

	private void drawWinSing(Graphics g) {
		g.setColor(Color.GREEN);
		Font font = new Font(g.getFont().getName(), Font.ITALIC, 20);
		g.setFont(font);
		g.drawString("You WIN!", 375, 105);
		g.setColor(Color.BLACK);
		g.setFont(font.deriveFont(Font.PLAIN, 11));
		g.drawString("Press RESTART.", 375, 120);
	}

}
